package yz.cp.back.s.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import yz.cp.back.s.entity.SysPermission;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author jobob
 * @since 2019-04-03
 */
public interface SysPermissionMapper extends BaseMapper<SysPermission> {
    /**
     * 通过用户id获取
     * @param userId
     * @return
     */
    @Select("  SELECT DISTINCT p.id, p.name, p.title, p.path, p.icon, p.type, p.component, p.level, p.button_type, p.parent_id, p.sort_order, p.description, p.status, p.url\n" +
            "      FROM sys_user u\n" +
            "      LEFT JOIN sys_user_role ur ON u.id = ur.user_id\n" +
            "      LEFT JOIN sys_role_permission rp ON ur.role_id = rp.role_id\n" +
            "      LEFT JOIN sys_permission p ON p.id = rp.permission_id\n" +
            "      WHERE u.id = #{userId} AND p.status = 0\n" +
            "      ORDER BY p.sort_order ASC")
    List<SysPermission> findByUserId(@Param("userId") String userId);
}
